home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 001a / com_and3.zip / HOST.SRC < prev    next >
Text File  |  1989-10-03  |  13KB  |  538 lines

  1.     ASSIGN S0 "****"        ; This is the logon password we'll use
  2.     ASSIGN S3 "xxxx"        ; This is the DOS password we'll use
  3. ;    trace on        ; Debugging
  4. ;
  5. ; ----- COM-AND Scripted host mode ----------------------------------
  6. ;
  7. ;    Goals:
  8. ;    o    Must autodetect caller's baud rate
  9. ;    o    Must work correctly for modems reporting true CD and otherwise.
  10. ;    o    Must log all activity
  11. ;
  12. ;    Functions:
  13. ;    o    Passworded log-on
  14. ;    o    DIR of current directory
  15. ;    o    CHDIR command
  16. ;    o    UP and DOWNLOADS
  17. ;    o    Graphical path display (using P/D TREED program)
  18. ;    o    Passworded DOS access (dangerous!)
  19. ;
  20. ;    Commenced: 10/29/87 R.McG
  21. ;    Updated:    2/--/89 R.McG
  22. ;           10/--/89 R.McG  ZMODEM added
  23. ;    --------------------------------------------------------------
  24. ;    Initialize
  25. ;
  26.     LEGEND "Scripted host mode.  Press ESC to exit, and then hangup."
  27.     SET BAUD 1200
  28.     SET PARITY NONE
  29.     SET DATA 8
  30.     SET STOP 1
  31.     SET PORT COM2
  32.     SET ALARM OFF            ; Turn off alarm
  33.     SET ATIME 1            ; Set alarm time to 1 second
  34.     SET ASCII UP_LF LF        ; Send LFs
  35.     TRANSMIT "~~~+++~~~ATZ^M"       ; Initialize modem
  36.     SET MASK ON            ; Set 7-bit masking
  37.     LOG MARK ON            ; Timestamp logging
  38.     SUBDIR S2            ; Save starting subdir
  39.     CLOG "* Host script loaded"
  40.     GOTO Restart            ; Branch around subroutines
  41. ;
  42. ;    Subroutine: Read from the caller into S9
  43. ;    .. This handles 'disconnect' and timeouts.
  44. ;
  45. Read_Comm:
  46.     RGET S9 80 180        ; wait for a connection
  47.     IF NOT CONNECTED    ; If modem reports CD dropped
  48.        GOTO Disconnect    ; Goto disconnect
  49.        ENDIF
  50.  
  51.     IF NOT SUCCESS        ; If timeout on the RGET
  52.        GOTO Timeout     ; .. issue message and disconnect
  53.     ENDIF
  54.  
  55.     FIND S9 "NO CARRIER"    ; Test for message from modem
  56.     IF FOUND        ; If modem didn't report 'CD' true
  57.        GOTO Disconnect    ; Goto disconnect
  58.        ENDIF
  59.  
  60.     SET FLAG(0) OFF     ; Report to caller
  61.     RETURN            ; Return with text in S9
  62. ;
  63. ;    Timeout on the call
  64. ;
  65. Timeout:
  66.     TRAN "^M^J... autodisconnect due to timeout"
  67.     MESSAGE "^M^J... autodisconnect due to timeout"
  68.     GOTO RComm_Exit     ; Exit cycle in the usual manner
  69. ;
  70. ;    Disconnect was reported.
  71. ;
  72. Disconnect:
  73.     MESSAGE  "^M^JCaller disconnected"
  74. ;
  75. ;    Read_Comm error exit
  76. ;
  77. RComm_Exit:
  78.     SET FLAG(0) ON        ; Report to caller
  79.     RETURN            ; Return to the caller
  80. ;
  81. ;    Usages:
  82. ;      S0 -> main password
  83. ;      S1 -> ID
  84. ;      S2 -> Default drive/subdir
  85. ;      S3 -> DOS password
  86. ;      S8 -> File name buffer
  87. ;      S9 -> General read buffer
  88. ;
  89. ;    Begin the sequence...
  90. ;
  91. Restart:
  92.     CHDIR S2        ; Reset to default drive
  93.     SET RECHO OFF        ; Turn off echo for us
  94.     CLEAR            ; Clear screen
  95.     LOCATE 0,0        ; Set to home
  96. ;
  97. ;    Go into auto answer (echo off, answer on 3rd)
  98. ;    Also: Return result codes, word form, with CONNECT 1200
  99. ;
  100. ;
  101.     MESSAGE "^M^JWaiting..."
  102.     Pause 3         ; Wait 3 seconds
  103.     HANGUP            ; HANGUP and leave modem in cmd mode
  104.     PAUSE 3         ; Wait 3 secs
  105.     TRANSMIT "ATE0Q0V1X1S0=2 S7=30 S9=10^M"
  106. ;
  107. ;    Wait for a connect
  108. ;
  109. WAIT_IT_OUT:
  110.     RGET S9 80 180
  111.     IF NOT SUCCESS
  112.        GOTO Wait_IT_Out
  113.        ENDIF
  114.  
  115.     FIND S9 "NO CARRIER"
  116.     IF FOUND
  117.        GOTO Restart
  118.        ENDIF
  119.  
  120.     FIND S9 "CONNECT"
  121.     IF NOT FOUND
  122.        GOTO WAIT_IT_OUT
  123.        ENDIF
  124.  
  125. ;***    IF NOT CONNECTED
  126. ;***       GOTO Wait_IT_Out
  127. ;***       ENDIF
  128. ;
  129. ;    Connection established: Adjust our linespeed if need be
  130. ;
  131.     GOSUB AutoBaud        ; Change rate according to CONNECT MSG
  132. ;
  133. ;    Issue a greeting
  134. ;
  135.     TRAN "^M^JThe Flying Scotsman greets you!!"
  136.     SET RECHO ON        ; Turn on echo (back to caller)
  137.     LOG OPEN "HOSTLOG"
  138. ;
  139. ;    Request an ID
  140. ;
  141. ID_Query:
  142.     TRANSMIT "^M^JEnter your ID: "
  143.  
  144.     GOSUB Read_Comm     ; Read into S9
  145.     IF FLAG(0)        ; If first flag rtns set
  146.        GOTO Exit        ; .. disconnect and start over
  147.        ENDIF        ; ..
  148.  
  149.     SWITCH S9
  150.        CASE "_NULL"         ; Test for nothing entered
  151.           TRAN "You must be someone^M^J"
  152.           GOTO Exit     ; Don't let noone in
  153.       ENDCASE        ; End of ridicule
  154.     ENDSWITCH        ; End of ID test
  155.  
  156.     CLOG "* Host mode logon by "*S9
  157. ;
  158. ;    Request a password
  159. ;
  160.     TRANSMIT "^M^JEnter your password: "
  161.     LOG SUSPEND
  162.     SET RECHO OFF        ; Turn of echo of received text
  163.     SET RDISPLAY OFF    ; Turn off echo to console too
  164.  
  165.     GOSUB Read_Comm     ; Read into S9
  166.     IF FLAG(0)        ; If first flag rtns set
  167.        GOTO Exit        ; .. disconnect and start over
  168.        ENDIF        ; ..
  169.  
  170.     LOG RESUME        ; Restore logging
  171.     SET RECHO ON        ; Restore echo
  172.     SET RDISPLAY ON     ; Turn on echo to console again
  173. ;
  174. ;    Test for the main password
  175. ;
  176.     SWITCH S9
  177.        CASE S0        ; Test for match with S0
  178.           TRANSMIT "^M^J"   ; OK - good password
  179.        ENDCASE        ; End match with S0
  180.        DEFAULT        ; Not one of the above
  181.           TRANSMIT "Sorry , but you're not authorized."
  182.           GOTO Exit     ; And disconnect
  183.        ENDCASE        ; End of DEFAULT
  184.     ENDSWITCH
  185. ;
  186. ;    Now - do something
  187. ;
  188. Main_Prompt:
  189.     MESS "^M^JMain prompt"  ; Local console indicator
  190.     TRAN "^M^JC)hdir F)ilelist, P)athlist, U)pload, D)ownload, or E)xit: "
  191.  
  192.     GOSUB Read_Comm     ; Read into S9
  193.     IF FLAG(0)        ; If first flag rtns set
  194.        GOTO EXIT        ; .. disconnect and start over
  195.        ENDIF        ; ..
  196.  
  197.     SWITCH S9        ; Test the entry
  198.        CASE "C"
  199.           GOTO CHDIR
  200.        ENDCASE
  201.  
  202.        CASE "D"
  203.           GOTO DOWNLOAD
  204.        ENDCASE
  205.  
  206.        CASE "E"
  207.           TRAN "Ok... bye"
  208.           GOTO EXIT
  209.        ENDCASE
  210.  
  211.        CASE "F"
  212.           GOTO FILELIST
  213.        ENDCASE
  214.  
  215.        CASE "P"
  216.           GOTO PATHLIST
  217.        ENDCASE
  218.  
  219.        CASE "U"
  220.           GOTO UPLOAD
  221.        ENDCASE
  222.  
  223.        CASE "X"
  224.           GOTO DOS
  225.        ENDCASE
  226.  
  227.        CASE "OFF"
  228.           TRAN "Ok... bye"
  229.           GOTO EXIT
  230.        ENDCASE
  231.     ;
  232.     ;    Default case for typists
  233.     ;
  234.        DEFAULT
  235.           FIND S9 "CHDIR"   ; Try for larger
  236.           IF FOUND        ; If entry contained "CHDIR"
  237.          GOTO CHDIR
  238.          ENDIF
  239.  
  240.           FIND S9 "DOWN"    ; Try for larger
  241.           IF FOUND        ; If entry contained 'Down"
  242.          GOTO DOWNLOAD
  243.          ENDIF
  244.  
  245.           FIND S9 "FILE"    ; Try for larger
  246.           IF FOUND        ; If entry contained 'FILE"
  247.          GOTO FILELIST
  248.          ENDIF
  249.  
  250.           FIND S9 "PATH"    ; Try for larger
  251.           IF FOUND        ; If entry contained 'PATH"
  252.          GOTO PATHLIST
  253.          ENDIF
  254.  
  255.           FIND S9 "UP"      ; Try for larger
  256.           IF FOUND        ; If entry contained 'up"
  257.          GOTO UPLOAD
  258.          ENDIF
  259.  
  260.           FIND S9 "DOS"     ; Try for larger
  261.           IF FOUND        ; If entry contained 'DOS"
  262.          GOTO DOS
  263.          ENDIF
  264.  
  265.           TRAN "^M^JCommand not recognized... try again"
  266.           GOTO Main_Prompt    ; If none of the above
  267.        ENDCASE        ; End of DEFAULT
  268.     ENDSWITCH
  269. ;
  270. ;    Can't get here because of the DEFAULT in the SWITCH above
  271. ;
  272.     TRAN "^M^JThank you veddy much.^M^J"
  273.     GOTO Main_Prompt
  274. ;
  275. ;    General exit routine - don't GOTO from within a subroutine!!!
  276. ;
  277. EXIT:
  278.     CLOG "* Host mode exit"
  279.     LOG CLOSE        ; Turn off logging
  280.     MESS "^G"               ; Beep to indicate completion
  281.     GOTO Restart        ; And start over
  282. ;
  283. ;    Subroutine: Query for a file name - return in S8
  284. ;
  285. File_Query:
  286.     MESS "^M^JFname query"  ; Local console indicator
  287.     TRAN "^M^JEnter the file name: "
  288.  
  289.     GOSUB Read_Comm     ; Read into S9
  290.     IF FLAG(0)        ; If first flag rtns set
  291.        RETURN        ; .. disconnect and start over
  292.        ENDIF        ; ..
  293.  
  294.     ASSIGN S8 S9        ; Move fname into another variable
  295.     SWITCH S8
  296.        CASE "_NULL"         ; Test for nothing entered
  297.           SET FLAG(1) ON    ; Report to caller
  298.           RETURN        ; Return right here w/ flag set
  299.        ENDCASE
  300.     ENDSWITCH        ; End of ID test
  301.  
  302.     SET FLAG(1) OFF     ; Report to caller
  303.     RETURN            ; Return to caller
  304. ;
  305. ;    XMODEM Upload (up from caller)
  306. ;
  307. UPLOAD:
  308.     MESS "^M^JUpload from caller"
  309.  
  310.     GOSUB File_Query    ; Ask for a file name
  311.     IF FLAG(0)        ; If first flag rtns set
  312.        GOTO EXIT        ; .. disconnect and start over
  313.        ENDIF        ; ..
  314.  
  315.     IF FLAG(1)        ; If no file returned
  316.        GOTO Main_Prompt    ; .. start over
  317.        ENDIF        ; ..
  318.  
  319.  
  320.     ISFILE S8        ; Test for file already
  321.     IF SUCCESS        ; If file exists
  322.        TRAN "^M^JFile already exists"
  323.        GOTO UPLOAD        ; Ask again
  324.        ENDIF
  325.  
  326.     MESS "^M^JMethod prompt"; Local console indicator
  327.     TRAN "^M^JW)xmodem, X)modem, Y)modem (X1k), Z)modem, or K)ermit: "
  328.  
  329.     GOSUB Read_Comm     ; Read into S9
  330.     IF FLAG(0)        ; If first flag rtns set
  331.        GOTO Main_Prompt    ; .. disconnect and start over
  332.        ENDIF        ; ..
  333.  
  334.     SWITCH S9        ; Test the entry
  335.        CASE "W"
  336.           GETFILE WXMODEM S8
  337.        ENDCASE
  338.        CASE "X"
  339.           GETFILE XMODEM S8
  340.        ENDCASE
  341.        CASE "Y"
  342.           GETFILE YMODEM S8
  343.        ENDCASE
  344.        CASE "Z"
  345.           GETFILE ZMODEM
  346.        ENDCASE
  347.        CASE "K"
  348.           GETFILE KERMIT    ; FIle name supplied by caller
  349.        ENDCASE
  350.        DEFAULT
  351.           TRAN "^M^JInvalid transfer selection"
  352.           GOTO Main_Prompt
  353.        ENDCASE
  354.     ENDSWITCH
  355.  
  356.     GOTO EOTransfer         ; Report success/failure
  357. ;
  358. ;    XMODEM Download (down to caller)
  359. ;
  360. DOWNLOAD:
  361.     MESS "^M^JDownload to caller"
  362.  
  363.     GOSUB File_Query    ; Ask for a file name
  364.     IF FLAG(0)        ; If first flag rtns set
  365.        GOTO EXIT        ; .. disconnect and start over
  366.        ENDIF        ; ..
  367.  
  368.     IF FLAG(1)        ; If no file returned,
  369.        GOTO Main_Prompt    ; .. start over
  370.        ENDIF        ; ..
  371.  
  372.     ISFILE S8        ; Test for file already
  373.     IF NOT SUCCESS        ; If file doesn't exist
  374.        TRAN "^M^JFile doesn't exist"
  375.        GOTO DOWNLOAD    ; Ask again
  376.        ENDIF
  377.  
  378.     MESS "^M^JMethod prompt"
  379.     TRAN "^MW)xmodem, X)modem, Y)modem (X1k), Z)modem, K)ermit, or A)scii: "
  380.  
  381.     GOSUB Read_Comm     ; Read into S9
  382.     IF FLAG(0)        ; If first flag rtns set
  383.        GOTO Main_Prompt    ; .. disconnect and start over
  384.        ENDIF        ; ..
  385.  
  386.     SWITCH S9        ; Test the entry
  387.        CASE "A"
  388.           SENDFILE ASCII S8
  389.        ENDCASE
  390.        CASE "W"
  391.           SENDFILE WXMODEM S8
  392.        ENDCASE
  393.        CASE "X"
  394.           SENDFILE XMODEM S8
  395.        ENDCASE
  396.        CASE "Y"
  397.           SENDFILE YMODEM S8
  398.        ENDCASE
  399.        CASE "Z"
  400.           SENDFILE ZMODEM S8
  401.        ENDCASE
  402.        CASE "K"
  403.           SENDFILE KERMIT S8
  404.        ENDCASE
  405.        DEFAULT
  406.           TRAN "^M^JInvalid transfer selection"
  407.           GOTO Main_Prompt
  408.        ENDCASE
  409.     ENDSWITCH
  410.  
  411.     GOTO EOTransfer         ; Report success/failure
  412. ;
  413. ;    End of transfer... note result on local console
  414. ;
  415. EOTRANSFER:
  416.     IF NOT SUCCESS
  417.        MESS "^M^JTransfer failed"
  418.     ELSE
  419.        MESS "^M^JTransfer OK"
  420.        ENDIF
  421.     GOTO Main_Prompt
  422. ;
  423. ;    Filelist... awkward... but it works
  424. ;
  425. FILELIST:
  426.     MESS "^M^JFilelist command"     ; Local console indicator
  427.     TRAN "^M^J Working..."          ; May take a moment
  428.  
  429.     DOS "DIR >HOSTTEMP.TXT"         ; To a temp file
  430.     TRAN "^M^J"                     ; Send a c/r
  431.     SENDFILE ASCII "HOSTTEMP.TXT"
  432.     TRAN "^M^J"                     ; Send a c/r
  433.  
  434.     DOS "DEL HOSTTEMP.TXT"          ; Clean up after us
  435.     GOTO Main_Prompt        ; And continue
  436. ;
  437. ;    CHDIR... Query for a path.
  438. ;
  439. CHDIR:
  440.     MESS "^M^JCHDIR Command"        ; Local console indicator
  441.     TRAN "^M^JEnter the drive:subdirectory: "
  442.  
  443.     GOSUB Read_Comm     ; Read into S9
  444.     IF FLAG(0)        ; If first flag rtns set
  445.        GOTO Main_Prompt    ; .. disconnect and start over
  446.        ENDIF        ; ..
  447.  
  448.     CHDIR S9        ; Do it.
  449.     GOTO Main_Prompt    ; And continue
  450. ;
  451. ;    Path tree... awkward... but it works
  452. ;
  453. PATHLIST:
  454.     MESS "^M^JPathlist command" ; Local console indicator
  455.     TRAN "^M^J Working..."  ; May take a moment
  456.  
  457.     DOS "Treed >HOSTTEMP.TXT" ; To a temp file
  458.     TRAN "^M^J"             ; Send a c/r
  459.     SENDFILE ASCII "HOSTTEMP.TXT"
  460.     TRAN "^M^J"             ; Send a c/r
  461.  
  462.     DOS "DEL HOSTTEMP.TXT"  ; Clean up after us
  463.     GOTO Main_Prompt    ; And continue
  464. ;
  465. ;    DOS command: Request a password
  466. ;
  467. DOS:
  468.     MESSAGE "^M^JRequesting DOS password"
  469.     LOG SUSPEND        ; Turn off logging
  470.     SET RECHO OFF        ; .. and don't echo passsword
  471.     SET RDISPLAY OFF    ; Turn off echo to console too
  472.  
  473.     TRANSMIT "^M^JEnter the DOS password: "
  474.  
  475.     GOSUB Read_Comm     ; Read into S9
  476.     IF FLAG(0)        ; If first flag rtns set
  477.        GOTO Main_Prompt    ; .. disconnect and start over
  478.        ENDIF        ; ..
  479.  
  480.     LOG RESUME        ; Turn on logging again
  481.     SET RECHO ON        ; .. and begin echoing again
  482.     SET RDISPLAY ON     ; Turn on echo to console again
  483. ;
  484. ;    Test for the our password
  485. ;
  486.     SWITCH S9
  487.        CASE S3        ; Test for match with S3
  488.           TRANSMIT "^M^J"   ; OK - good password
  489.        ENDCASE        ; End match with S3
  490.        DEFAULT        ; Not one of the above
  491.           TRANSMIT "Sorry , but you're not authorized."
  492.           GOTO Main_Prompt    ; And continue
  493.        ENDCASE        ; End of DEFAULT
  494.     ENDSWITCH
  495.     LOG RESUME
  496. ;
  497. ;    DOS... Query for a command
  498. ;
  499.     MESS "^M^JDOS Command"  ; Local console indicator
  500.     TRAN "^M^JEnter the command: "
  501.  
  502.     GOSUB Read_Comm     ; Read into S9
  503.     IF FLAG(0)        ; If first flag rtns set
  504.        GOTO Main_Prompt    ; .. disconnect and start over
  505.        ENDIF        ; ..
  506.  
  507.     TRAN "^M^J Working..."  ; May take a moment
  508.  
  509.     CONCAT S9 ">HOSTTEMP.TXT"
  510.     DOS   S9        ; Do it.
  511.  
  512.     TRAN "^M^J"             ; Send a c/r
  513.     SENDFILE ASCII "HOSTTEMP.TXT"
  514.     TRAN "^M^J"             ; Send a c/r
  515.  
  516.     DOS "DEL HOSTTEMP.TXT"  ; Clean up after us
  517.     GOTO Main_Prompt    ; And continue
  518. ;
  519. ;    Auto baudrate detect (according to message in S9)
  520. ;
  521. AutoBaud:
  522.     FIND S9 "1200"          ; Test for 1200 baud
  523.     IF FOUND        ; IF found
  524.        SET BAUD 1200    ; Set to 1200 baud
  525.        RETURN        ; We're done.
  526.        ENDIF
  527.  
  528.     FIND S9 "2400"          ; Test for 1400 baud
  529.     IF FOUND        ; IF found
  530.        SET BAUD 2400    ; Set to 1400 baud
  531.        RETURN        ; We're done.
  532.        ENDIF
  533. ;
  534. ;    None of the above... set to 300
  535. ;
  536.     SET BAUD 300        ; Set to 1200 baud
  537.     RETURN            ; We're done.
  538.